package com.loe.test

import com.loe.http.Link
import kotlinx.coroutines.*

suspend fun Link.await() = withIOContext { syncBean() }

suspend fun Link.awaitFile() = withIOContext { syncGetFile() }

suspend fun Link.awaitResponse() = withIOContext {
    if (type == "get")
    {
        syncResponseGet()
    } else
    {
        syncResponseBody()
    }
}

suspend fun Link.awaitGet() = withIOContext { syncGet() }

suspend fun Link.awaitGetFile() = withIOContext { syncGetFile() }

suspend fun Link.awaitPost() = withIOContext { syncPost() }

suspend fun Link.awaitPut() = withIOContext { syncPut() }

suspend fun Link.awaitDelete() =  withIOContext { syncDelete() }

suspend fun <T> withMainContext(block: suspend CoroutineScope.() -> T): T
{
    return withContext(Dispatchers.Main, block)
}

suspend fun <T> withIOContext(block: suspend CoroutineScope.() -> T): T
{
    return withContext(Dispatchers.IO, block)
}